package org.wat.wcy.isi.mmazur.bp.io.xpdl;

import java.io.File;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.apache.commons.lang.StringUtils;
import org.wat.wcy.isi.mmazur.bp.io.core.IDataProvider;
import org.wat.wcy.isi.mmazur.bp.io.parsers.IParser;

public class XPDLParser implements IParser {

	@Override
	public IDataProvider loadModel(final File projectDir, final String fileName) {
		if (StringUtils.isEmpty(fileName)) {
			throw new IllegalStateException(
					"Parameter 'String fileName' is NULL!");
		}
		
		File file = new File(fileName);
		
		SAXParserFactory factory = SAXParserFactory.newInstance();
		try {
			SAXParser saxParser = factory.newSAXParser();
			XPDLHandler xpdlHandler = new XPDLHandler();
			saxParser.parse(file, xpdlHandler);
			return xpdlHandler;
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return null;
	}
}